package org.dtrd.modules.service.entity.bean;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.dtrd.common.util.DateUtils;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.archive.entity.po.DtrdEntRdArchiveReverseScheme;
import org.dtrd.modules.patient.entity.po.DtrdEntRdPatient;
import org.dtrd.modules.service.entity.po.DtrdEntRdServicePackage;
import org.dtrd.modules.service.entity.po.DtrdRlPackagePatient;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * @author qr
 * @date 2022/1/10 13:04
 */
@ApiModel("患者服务详情的信息")
@Getter
@Setter
public class PatientServiceRelationInfo {

    @ApiModelProperty("服务名称")
    private String serviceName;

    @ApiModelProperty("服务包名称")
    private String packageName;

    @ApiModelProperty("服务包描述名称")
    private String packageDesc;

    @ApiModelProperty("服务包图片")
    private String servicePhoto;

    @ApiModelProperty("知情同意书")
    private String consentImage;

    @ApiModelProperty("服务协议")
    private String protocolImage;

    @ApiModelProperty("服务包状态，0-没有服务，1-服务中，2-待服务，3-已结束")
    private Integer serviceStatus;

    @ApiModelProperty("服务包状态文本")
    private String serviceStatusText;

    @ApiModelProperty(value = "管理成效")
    @NotEmpty
    @Valid
    private List<ManageEffect> manageEffect;

    @ApiModelProperty("客户名字")
    private String clientName;

    @ApiModelProperty("医生")
    private String doctorName;

    @ApiModelProperty("健康管理师")
    private String healthManager;

    @ApiModelProperty("营养师")
    private String dietician;

    @ApiModelProperty("心理咨询师")
    private String psychologicalCounselor;

    @ApiModelProperty("运动康复师")
    private String sportManager;

    @ApiModelProperty("有效期")
    private String validPeriod;

    public PatientServiceRelationInfo parseFromPO(DtrdEntRdPatient po) {
        clientName = po.getPatientsName();
        return this;
    }

    public PatientServiceRelationInfo parseFromPO(DtrdEntRdServicePackage po) {
        serviceName = po.getPackageName();
        servicePhoto = po.getPackageThumb();
        packageDesc = po.getPackageDesc();
        if (StrUtil.isNotBlank(po.getManageEffect())) {
            manageEffect = JSON.parseArray(po.getManageEffect(), ManageEffect.class);
        }
        return this;
    }

    public PatientServiceRelationInfo parseFromPO(DtrdRlPackagePatient po) {
        Date startTime = po.getStartTime();
        Date endTime = po.getEndTime();
        validPeriod = DateUtils.combineTwoTime(startTime, endTime);
        Integer status = po.getStatus();
        Optional.ofNullable(status).ifPresent(s -> {
            this.serviceStatus = s;
            this.serviceStatusText = Constant.PackageServiceStatus.valueOf(s).getName();
        });
        return this;
    }

    public void parseFromPO(DtrdEntRdArchiveReverseScheme reverseScheme) {
        if (reverseScheme != null) {
            protocolImage = reverseScheme.getProtocolImage();
            consentImage = reverseScheme.getConsentImage();
        }
    }
}
